import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { HttpExceptionFilter } from "./common/filter/http-exception/http-exception.filter";
import { TransformInterceptor } from "./common/interceptor/transform/transform.interceptor";
import { AppModule } from './app.module';
import { ValidationPipe } from './common/filter/http-exception/validate.pipe';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .addBearerAuth()
    .setTitle('NeuroCore')
    .setDescription('The cats API description')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);


  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalFilters(new HttpExceptionFilter());
  // app.useGlobalInterceptors(new TransformInterceptor());

  // 设置端口
  const port = process.env.PORT || 3000; // 从环境变量或默认端口3000中获取端口号
  app.enableCors();
  await app.listen(port); // 监听指定端口

  console.log(`Application is running on port http://127.0.0.1:${port}`);
}
bootstrap();
